package com.matt.repository.impl;

import com.matt.foundation.DO.NonProcessCourseItemDO;
import com.matt.foundation.constant.ChildrenCourseConstant;
import com.matt.repository.base.BaseNativeSqlRepository;
import com.matt.repository.base.CoursePlanItemRepository;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/9/8
 * *******************************
 */
@Component
public class CoursePlanItemRepositoryImpl extends BaseNativeSqlRepository implements CoursePlanItemRepository {
    @Override
    public List<Object[]> findByChildrenCourseIdAndStatus(String childrenCourseId) {
        String findSql=String.format("select i.id , p.courseName, p.courseDate, p.typeName, i.status, p.id as planId " +
                " from children_course_item i left join course_plan p on i.coursePlanId = p.id " +
                " where i.childrenCourseId = '%s' and i.status =%s", childrenCourseId, ChildrenCourseConstant.ItemStatus.NON_USED.codeOf());
        List<Object[]> objectArrayList = sqlArrayList(findSql);
        return objectArrayList;
    }

    @Override
    public List<NonProcessCourseItemDO> findByStatusAndCourseDate(Integer status, String begDate, String endDate) {
        String findSql=String.format("select i.id as childrenCourseItemId, i.childrenId as childrenId, i.status as status, p.areaId as areaId, p.courseName as courseName, p.courseDate as courseDate" +
                " from children_course_item i left join course_plan_classes p on i.coursePlanId = p.id " +
                " where i.status = '%s' and p.courseDate >= '%s' and p.courseDate <= '%s'" , status, begDate, endDate);
        List<NonProcessCourseItemDO> objectArrayList = sqlObjectList(findSql, NonProcessCourseItemDO.class);
        return objectArrayList;
    }
}
